
version 15
capture log close
set more off
clear
clear matrix
clear mata

if c(username)=="WB485280" {
		glo rootdir		"C:\Users\wb485280\OneDrive - WBG\radicalization"
		}
if c(username)=="WB382635" {
		glo rootdir		"C:\Users\wb382635\Dropbox\Unemp & daesh"
		}
if c(username)=="WB452275" {
		glo rootdir		"C:\Users\WB452275\Dropbox\Projects\Unemp & daesh"
		}
if c(username)=="sarurchaudhary" {
		glo rootdir		"/Users/sarurchaudhary/Dropbox/Unemp & daesh"
		}
if c(username)=="kartikabhatia" {
			glo rootdir		"/Users/kartikabhatia/Dropbox/Before2019/Unemp & daesh"
			}
			
		glo	datadir     "${rootdir}/Data/Raw data"
		glo outdir		"${rootdir}/Data/Working datasets"
		glo dodir		"${rootdir}/Dofiles"
        
		cd "${outdir}"
		
	
	    log using gallup2_prep, replace t



* ------------------------------------------------------------------------------
* Date : July 2017 [chkd oct 2021]


* Project : Working Paper, MEM (MNACE, The World Bank)


* This do file prepares the index variables from the Gallup database for merge

* Database used : The_Gallup_032516.dta.dta


* Output : gallup2.dta

* ------------------------------------------------------------------------------

use "${datadir}/The_Gallup_032516.dta", clear
rename WP* wp*

* Collapsing data to create country level estimates (keeping the same labels)


foreach v of var INDEX_CA - INDEX_YD {
 	local l`v' : variable label `v'
        if `"`l`v''"' == "" {
 		local l`v' "`v'"
  	}
  }
collapse INDEX_CA - INDEX_YD [pw=wgt], by(countrynew YEAR_CALENDAR)


 foreach v of var INDEX_CA - INDEX_YD {
 	label var `v' "`l`v''"
 }


* ------------------------------------------------------------------------------

*************************************
*       Renaming Variables
*************************************

rename YEAR_CALENDAR year

* Adding countries that are in WDI but not in gallup

insobs 55, before(1)
 replace countrynew = "Equatorial Guinea" in 1/11
 replace year = 2005 in 1
 replace year = year[_n-1]+1  in 2/11

 replace countrynew = "Eritrea" in 12/22
 replace year = 2005 in 12
 replace year = year[_n-1]+1  in 13/22

 replace countrynew = "Gambia, The" in 23/33
 replace year = 2005 in 23
 replace year = year[_n-1]+1  in 24/33

 replace countrynew = "Guinea-Bissau" in 34/44
 replace year = 2005 in 34
 replace year = year[_n-1]+1  in 35/44

 replace countrynew = "North Korea" in 45/55
 replace year = 2005 in 45
 replace year = year[_n-1]+1  in 46/55


 * Creating numeric variable for countries

sort countrynew, stable
encode countrynew, gen(ctry)

sort ctry year

save "${outdir}/gallup2.dta", replace

log close
